package org.diffshop.common.annotation;

import jakarta.validation.Constraint;
import jakarta.validation.Payload;
import org.diffshop.common.valid.ConstraintListValValidator;

import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
 * 自定义参数校验注解的过程
 * 1 定义注解如：ListVal(仿照其他同类注解)
 * 2 定义参数校验器
 */

/**
 * @Author:tjf
 * @Description: 校验参数是否在指定列表中
 */
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE })
@Retention(RUNTIME)
@Documented
@Repeatable(ListVal.List.class)
@Constraint(validatedBy = {ConstraintListValValidator.class})
public @interface ListVal {
    String message() default "{org.diffshop.common.annotation.ListVal.message}";

    Class<?>[] groups() default { };

    Class<? extends Payload>[] payload() default { };

    int[] value() default {};

    @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE })
    @Retention(RUNTIME)
    @Documented
    public @interface List {
        ListVal[] value();
    }
}
